<?php
 require_once '../model/Examen.php';
class ExamenManager {
    //put your code here
     private $bdd;
     
     function __construct($bdd) {
        $this->bdd = $bdd;
    }
    
    
    public function add(Examen $examen) {

        $q = $this->bdd->prepare('INSERT INTO EXAMENS (idCat, idClasse, date, libelle) VALUES(:idCat, :idClasse, :date, :libelle)');
        $q->bindValue(':idCat', $examen->getIdCategorie());
        $q->bindValue(':idClasse', $examen->getIdClasse());
        $q->bindValue(':date', $examen->getDate());
        $q->bindValue(':libelle', $examen->getLibelle());
        $q->execute();
    }

    public function delete(Examen $examen) {
        $id = $examen->getIdExamen();
        $this->connexion();
        $bdd->exec('DELETE FROM EXAMENS WHERE idExamen= ' . $id);
    }
    
    
    public function getListExamen ($idClasse,$idUser) {
        $listExamen = array();
      //  $req = $this->bdd->prepare('SELECT * FROM PROJETS WHERE idClas='.$idClasse);
        $req = $this->bdd->prepare('SELECT * FROM EXAMENS WHERE idExamen NOT IN (select idExamen FROM ABON_EXAMEN WHERE idUser='.$idUser.') AND idClasse='.$idClasse );
        $req->execute();
        while ($donnees = $req->fetch()) {
            $examen = new Examen($donnees["idExamen"], $donnees["idCat"],$donnees["idClasse"], $donnees["date"],$donnees["libelle"] );
            array_push($listExamen, $examen);
        }
        return $listExamen;
        
    }
    
    public function getList ($id) {
        $listExamen = array();
        $req = $this->bdd->prepare('SELECT * FROM EXAMENS WHERE idExamen='.$id);
        $req->execute();
        while ($donnees = $req->fetch()) {
            $examen = new Examen($donnees["idExamen"], $donnees["idCat"],$donnees["idClasse"], $donnees["date"],$donnees["libelle"] );
            array_push($listExamen, $examen);
        }
        return $listExamen;
        
    }
    
    public function  getDate ($idExamen) {
        $requete ="SELECT EXAMENS.date FROM EXAMENS WHERE EXAMENS.idExamen=$idExamen";
        $req = $this->bdd->prepare($requete);
        $req->execute();
        $donnees = $req->fetch();
      //  var_dump($donnees);
        $date =  $donnees['date'];
        //echo ucfirst($donnees["date"]);
        return $date;
    }
}
